package com.minggo.charmword.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.View;

import com.minggo.charmword.R;

/**
 * 截图控件
 * @author minggo
 * @date 2014-9-29 上午11:16:09
 */
public class CropImage extends View {
	private Paint mPaint1,mPaint2;
	private Paint mCropPaint;
	private Rect mBounds;

	private int mCount;
	private Context context;

	public CropImage(Context context, AttributeSet attrs) {
		super(context, attrs);
		mPaint1 = new Paint(Paint.ANTI_ALIAS_FLAG);
		mPaint2 = new Paint(Paint.ANTI_ALIAS_FLAG);
		mBounds = new Rect();
		this.context = context;
	}

	@Override
	protected void onDraw(Canvas canvas) {
		super.onDraw(canvas);
		// 设置
		int mwidth = getWidth()
				- (int) getResources().getDimension(
						R.dimen.dp_50) * 2;
		int mMiginTop = (int) getResources().getDimension(
						R.dimen.dp_48);
		// 设置阴影的背景色
		mPaint1.setColor(context.getResources().getColor(R.color.crop_bg));
		// 画上边部分的阴影
		canvas.drawRect(0, mMiginTop, getWidth(), getHeight() / 2
				- mwidth / 2, mPaint1);
		// 画左边部分的阴影
		canvas.drawRect(0, getHeight() / 2
				- mwidth / 2, getWidth() / 2 - mwidth / 2, getHeight() / 2
				+ mwidth / 2, mPaint1);
		// 画右边部分的阴影
		canvas.drawRect(getWidth() / 2
				+ mwidth / 2, getHeight() / 2
				-mwidth / 2, getWidth(), getHeight() / 2
				+mwidth / 2, mPaint1);
		// 画下边部分的阴影
		canvas.drawRect(0, getHeight() / 2
				+ mwidth / 2, getWidth(), getHeight() , mPaint1);
		mPaint2.setStyle(Paint.Style.STROKE);
		// 消除锯齿
		mPaint2.setAntiAlias(true);
		// 设置画笔的颜色
		mPaint2.setColor(Color.WHITE);
		// 设置paint的外框宽度
		mPaint2.setStrokeWidth(2);
		// 画中间部分的阴影
		canvas.drawRect(getWidth() / 2 - mwidth / 2, getHeight() / 2 - mwidth
				/ 2, getWidth() / 2 + mwidth / 2, getHeight() / 2 + mwidth / 2,
				mPaint2);
	}

}
